package ca.abubakrsagar.breadboardsim;

import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JPanel;

/**
 * 
 * This class deals with the panel that will hold all the components which can
 * be placed on the breadboard. It extends JPanel.
 * 
 * @author Sagar Desai, Mohammad Abubakr
 * @since May 29, 2012
 * 
 */
public class ComponentsPanel extends JPanel {

	// All the components to be placed on the components Panel.
	private LED ledComponent = new LED(Color.red);
	private Resistor resistorComponent = new Resistor(1000, 0);
	private Switch switchComponent = new Switch(false); 

	private ComponentsController compController = new ComponentsController(this); // The
																			// controller
																			// for
																			// the
																			// components
																			// Panel.
	private BreadboardPanel brPanel; // The breadboard object.

	/**
	 * 
	 * @param brPanel
	 *            The given breadboard panel.
	 */
	public ComponentsPanel(BreadboardPanel brPanel) {
		this.brPanel = brPanel;
		// Initializes the panel
		setPreferredSize(new Dimension(900 / 5, 253));
		this.setLayout(new GridLayout(4, 2, 5, 5));
		this.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
		setBorder(BorderFactory.createTitledBorder("Components"));
		setVisible(true);

		// Adds the components to the panel
		this.add(ledComponent);
		this.add(resistorComponent);
		this.add(switchComponent);

		// Adds mouse listeners to all components.
		ledComponent.addMouseListener(compController);
		resistorComponent.addMouseListener(compController);
		switchComponent.addMouseListener(compController);
	}

	/**
	 * @return The led component.
	 */
	public LED getLedComponent() {
		return ledComponent;
	}

	/**
	 * @return The resistor component.
	 */
	public Resistor getResistorComponent() {
		return resistorComponent;
	}

	/**
	 * @return The switch component.
	 */
	public Switch getSwitchComponent() {
		return switchComponent;
	}

	/**
	 * @return The Breadboard panel.
	 */
	public BreadboardPanel getBrPanel() {
		return brPanel;
	}

	/**
	 * Adds an LED onto the breadboard panel.
	 */
	public void addLED() {
		LED tempLED = new LED(Color.red);
		brPanel.addLED(tempLED);
	}

	/**
	 * Adds a resistor onto the breadboard panel.
	 */
	public void addResistor() {
		Resistor tempResistor = new Resistor(1000, 0);
		brPanel.addResistor(tempResistor);
	}

	/**
	 * Adds a switch onto the breadboard panel.
	 */
	public void addSwitch() {
		Switch tempSwitch = new Switch(false);
		brPanel.addSwitch(tempSwitch);
	}

}
